package com.yt.sys.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yt.sys.models.entity.SysAdminRole;
import com.yt.sys.models.service.ISysAdminRoleService;
import com.yt.sys.server.mapper.SysAdminRoleMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService(interfaceClass = ISysAdminRoleService.class)
public class SysAdminRoleServiceImpl extends ServiceImpl<SysAdminRoleMapper, SysAdminRole> implements ISysAdminRoleService {

    /**
     * 根据管理员ID获取角色关联列表
     * @param adminId 管理员ID
     * @return 角色关联列表
     */
    public List<SysAdminRole> getRolesByAdminId(Integer adminId) {
        QueryWrapper<SysAdminRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("admin_id", adminId);
        return this.list(queryWrapper);
    }

    /**
     * 根据角色ID获取管理员关联列表
     * @param roleId 角色ID
     * @return 管理员关联列表
     */
    public List<SysAdminRole> getAdminsByRoleId(Integer roleId) {
        QueryWrapper<SysAdminRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id", roleId);
        return this.list(queryWrapper);
    }

    /**
     * 删除管理员的所有角色关联
     * @param adminId 管理员ID
     * @return 是否操作成功
     */
    public boolean removeRolesByAdminId(Integer adminId) {
        QueryWrapper<SysAdminRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("admin_id", adminId);
        return this.remove(queryWrapper);
    }
}